package com.douqu.game.core.entity.ext;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.ext.data.boon.*;
import com.douqu.game.core.entity.ext.data.mall.MallData;
import com.douqu.game.core.factory.FunctionFactory;
import com.douqu.game.core.factory.WorldInfoFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.RechargeGuideUtils;
import com.douqu.game.core.util.CoreUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 福利信息
 * 祭坛,抽奖这种的信息全部保存在这里面
 * @Author: Bean
 * @Description:
 * @Date: 2017-10-30 10:29
 */
public class BoonInfo extends ExtInfo{

    //祭坛信息
    private AltarData altarData;

    //抽奖信息
    private LotteryData lotteryData;

    //商店信息
    private StoreData goblinStoreData;

    //充值信息
    private RechargeRecordData rechargeRecordData;

    //各种福利 比如首充等
    private BonusData bonusData;

    private MallData mallData;

    //分享数据
    private ShareData shareData;

    //在线奖励数据
    private OnlineRewardData onlineRewardData;
    //7天活动奖励数据
    private SevenDayData sevenDayData;


    public BoonInfo(Player player) {
        super(player);

        altarData = new AltarData(player);
        lotteryData = new LotteryData(player);
        goblinStoreData = new StoreData(player);
        rechargeRecordData = new RechargeRecordData(player);
        bonusData = new BonusData(player);
        mallData = new MallData(player);
        shareData = new ShareData(player);
        onlineRewardData = new OnlineRewardData(player);
        sevenDayData = new SevenDayData(player);
    }

    @Override
    public List<SGCommonProto.E_RED_POINT_TYPE> checkRedPointRemindAllCondition(long currentTime) {
        List<SGCommonProto.E_RED_POINT_TYPE> list = null;

        if(RechargeGuideUtils.isRechargeGuideShow(player)){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_RECHARGE_GUIDE);
        }

        if(CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_ALTAR_SYSTEM, player) && altarData.hasRedPointRemind()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_ALTAR);
        }

        if(CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_LOTTERY, player) && lotteryData.hasRedPointRemind(false, currentTime)){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_LOTTERY);
        }

        if(CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_GOBLIN_SHOP_SYSTEM, player) && goblinStoreData.hasRedPointRemind()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_GOBLIN_STORE);
        }

        if(rechargeRecordData.hasRedPointRemind()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_RECHARGE);
        }

        if(bonusData.hasRedPointRemind() || rechargeRecordData.hasDailyRewardGiftRedPoint()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_BONUS);
        }
        if(bonusData.checkLoginBonus()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_LOGIN_BONUS);
        }

        if(rechargeRecordData.isFirstRechargeComplete() && !bonusData.isFistRechargeReceive()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_FIRST_RECHARGE);
        }

        if(WorldInfoFactory.getInstance().getWorldAuctionData().redAuction()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_WORLD_ACUTION);
        }

        if(shareData.checkRedPoint()){
            if (list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_BONUS);
        }

        if (bonusData.redTimeActivity()){
            if (list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_TIME_LIMIT);
        }


//        if(onlineRewardData.checkRedPoint()){
//            if (list == null){
//                list = new ArrayList<>();
//            }
//            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_ONLINE_REWARD);
//        }

        return list;

    }


    @Override
    public void init()
    {
        altarData.init();
        lotteryData.init();
        goblinStoreData.init();
        rechargeRecordData.init();
        bonusData.init();
        mallData.init();
        shareData.init();
        onlineRewardData.init();
        sevenDayData.init();
    }

    @Override
    public void checkInit() {
        altarData.checkInit();
        lotteryData.checkInit();
        goblinStoreData.checkInit();
        rechargeRecordData.checkInit();
        bonusData.checkInit();
        mallData.checkInit();
        shareData.checkInit();
        onlineRewardData.checkInit();
        sevenDayData.checkInit();
    }

    @Override
    public void reset() {
        //检测重置
        altarData.reset();
        lotteryData.reset();
        goblinStoreData.reset();
        rechargeRecordData.reset();
        bonusData.reset();
        bonusData.resetDiamondsCache(); //这个方法只在reset中执行 checkReset不执行
        mallData.reset();
        shareData.reset();
        onlineRewardData.reset();
        sevenDayData.reset();
    }

    @Override
    public void checkReset() {
        //检测重置
        altarData.checkReset();
        lotteryData.checkReset();
        goblinStoreData.checkReset();
        rechargeRecordData.checkReset();
        bonusData.checkReset();
        mallData.checkReset();
        shareData.checkReset();
        onlineRewardData.checkReset();
        sevenDayData.checkReset();
    }

    @Override
    public void writeTo(ByteBuffer buffer)
    {
        altarData.writeTo(buffer);

        lotteryData.writeTo(buffer);

        goblinStoreData.writeTo(buffer);

        rechargeRecordData.writeTo(buffer);

        bonusData.writeTo(buffer);

        //+++++++++++++++++++++++++++++++++++++++++++++++++++++
        buffer.writeBoolean(true);//必须为true,不然mallData会报错

        mallData.writeTo(buffer);

        buffer.writeBoolean(true);

        shareData.writeTo(buffer);

        buffer.writeBoolean(true);

        onlineRewardData.writeTo(buffer);

        buffer.writeBoolean(true);

        sevenDayData.writeTo(buffer);

        buffer.writeBoolean(false);
    }

    @Override
    public void loadFrom(ByteBuffer buffer)
    {
        altarData.loadFrom(buffer);

        lotteryData.loadFrom(buffer);

        goblinStoreData.loadFrom(buffer);

        rechargeRecordData.loadFrom(buffer);

        bonusData.loadFrom(buffer);

        //+++++++++++++++++++++++++++++++++++++++++++++++++++++
        boolean flag = buffer.readBoolean();
        if(flag)
        {
            mallData.loadFrom(buffer);

            flag = buffer.readBoolean();

            if (flag)
            {
                shareData.loadFrom(buffer);

                flag = buffer.readBoolean();

                if (flag)
                {
                    onlineRewardData.loadFrom(buffer);

                    flag =buffer.readBoolean();

                    if (flag){
                        sevenDayData.loadFrom(buffer);

                        buffer.readBoolean();

                    }
                }

            }
        }
    }


    public AltarData getAltarData() {
        return altarData;
    }

    public LotteryData getLotteryData() {
        return lotteryData;
    }

    public StoreData getGoblinStoreData() {
        return goblinStoreData;
    }

    public RechargeRecordData getRechargeRecordData() {
        return rechargeRecordData;
    }

    public BonusData getBonusData() {
        return bonusData;
    }

    public MallData getMallData() {
        return mallData;
    }

    public ShareData getShareData() {
        return shareData;
    }

    public OnlineRewardData getOnlineRewardData() {
        return onlineRewardData;
    }

    public SevenDayData getSevenDayData() {
        return sevenDayData;
    }
}
